<template>
  <div class="container">
    <el-dialog
      title="题目审核"
      :visible="chkStatedialog"
      width="30%"
      @close="btncanel"
    >
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item prop="radio">
          <el-radio v-model="form.radio" label="2">通过</el-radio>
          <el-radio v-model="form.radio" label="1">拒绝</el-radio>
        </el-form-item>
        <el-form-item prop="textarea">
          <el-input
            style="margin-top: 20px"
            type="textarea"
            :rows="2"
            placeholder="请输入审核意见"
            v-model="form.textarea"
          >
          </el-input
        ></el-form-item>

        <el-row style="margin-top: 20px">
          <el-col align="right">
            <el-button @click="btncanel">取消</el-button>
            <el-button type="primary" @click="btnconfirm">确认</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions.js'
export default {
  name: 'Check',
  data () {
    return {
      textarea: '',
      form: {
        radio: '2',
        textarea: ''
      },
      rules: {
        textarea: [{ required: true, message: '请输入审核意见' }]
      }
    }
  },
  props: {
    chkStatedialog: {
      type: Boolean
    },
    list: {
      type: Object
    }
  },
  methods: {
    btncanel () {
      // 点击取消按钮 触发事件
      this.$emit('update:chkStatedialog', false)
      this.$refs.form.resetFields() // 清空校验规则
    },
    getid (id) {
      console.log(id)
      this.id = id
    },
    btnconfirm () {
      this.$refs.form.validate(async (isOk) => {
        if (isOk) {
          try {
            const res = await choiceCheck({
              id: this.id,
              chkState: parseInt(this.form.radio),
              chkRemarks: this.form.textarea
            })
            console.log(res)
            this.$emit('btnConfirm')// 更新视图
            this.$emit('update:chkStatedialog', false)
            this.$message.success('操作成功')
          } catch (error) {
            console.log(error)
          }
        }
      })
    }
  }
}
</script>

<style scoped lang='less'></style>
